package cn.gson.school.entity.xitong;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;

import lombok.Data;

@Entity
@Table(name = "tb_jx_resources")
@Data
@SuppressWarnings("unused")
public class ResourcesEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name="resource_id")
    private Long resourceId;

    @ManyToOne
    @JsonIgnore
    private ResourcesEntity parent;

    @Column(name="resource_name",nullable = false)
    private String resourceName;

    @Column(name = "permission_key", nullable = false, length = 32)
    private String permissionKey;

    /**

     * 权限类型

     */
    @Enumerated(EnumType.STRING)
    private Type type;

    /**

     * 菜单路径

     */
    @Column(name = "menu_path")
    private String menuPath;

    /**

     * 资源

     */
    private String resource;

    private Boolean enable = false;

    private String description;

    private Integer weight = 0;

    @OneToMany(cascade = CascadeType.REMOVE, mappedBy = "parent")
    private List<ResourcesEntity> children;

    @JsonProperty("value")
    public Long getValue() {
        return this.resourceId;
    }
    
    @JsonProperty("id")
    public Long getId() {
        return this.resourceId;
    }
    
    @JsonProperty("text")
    public String getText() {
        return this.resourceName;
    }

    /**

     * 权限类型枚举

     */
    public enum Type {
        MENU("菜单"),
        FUNCTION("功能"),
        BLOCK("区域");

        private String display;

        Type(String display) {
            this.display = display;
        }

        public String display() {
            return display;
        }

        @Override
        public String toString() {
            return this.display + "[" + this.name() + "]";
        }
    }

	public Long getResourceId() {
		return resourceId;
	}

	public void setResourceId(Long resourceId) {
		this.resourceId = resourceId;
	}

	public ResourcesEntity getParent() {
		return parent;
	}

	public void setParent(ResourcesEntity parent) {
		this.parent = parent;
	}

	public String getResourceName() {
		return resourceName;
	}

	public void setResourceName(String resourceName) {
		this.resourceName = resourceName;
	}

	public String getPermissionKey() {
		return permissionKey;
	}

	public void setPermissionKey(String permissionKey) {
		this.permissionKey = permissionKey;
	}

	public Type getType() {
		return type;
	}

	public void setType(Type type) {
		this.type = type;
	}

	public String getMenuPath() {
		return menuPath;
	}

	public void setMenuPath(String menuPath) {
		this.menuPath = menuPath;
	}

	public String getResource() {
		return resource;
	}

	public void setResource(String resource) {
		this.resource = resource;
	}

	public Boolean getEnable() {
		return enable;
	}

	public void setEnable(Boolean enable) {
		this.enable = enable;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Integer getWeight() {
		return weight;
	}

	public void setWeight(Integer weight) {
		this.weight = weight;
	}

	public List<ResourcesEntity> getChildren() {
		return children;
	}

	public void setChildren(List<ResourcesEntity> children) {
		this.children = children;
	}

	@Override
	public String toString() {
		return "ResourcesEntity [resourceId=" + resourceId + ", resourceName=" + resourceName + ", permissionKey="
				+ permissionKey + ", type=" + type + ", menuPath=" + menuPath + ", resource=" + resource + ", enable="
				+ enable + ", description=" + description + ", weight=" + weight + "]";
	}
    
}

